package com.xiaolun;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author 硕鼠
 * @Date 2020/5/10 17:49
 * @Version 1.0
 * @Description 不安全的集合
 */

//测试JUC安全类型的集合
public class TestJUC {
    public static void main(String[] args) throws InterruptedException {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                list.add(Thread.currentThread().getName());
            }).start();
        }

        Thread.sleep(1000);
        System.out.println(list.size());
    }
}
